package cn.vin.utils;

import io.netty.handler.ssl.ApplicationProtocolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;

public class RedisUtils {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    public static void main(String[] args) {
    }

    /*public boolean setIfAbsent(final String key, final Serializable value, final long exptime) {
        Boolean b = (Boolean) redisTemplate.execute(new RedisCallback<Boolean>() {
            @Override
            public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
                RedisSerializer valueSerializer = redisTemplate.getValueSerializer();
                RedisSerializer keySerializer = redisTemplate.getKeySerializer();
                Object obj = connection.execute("set", keySerializer.serialize(key),
                        valueSerializer.serialize(value),
//                        SafeEncoder.encode("NX"),
//                        SafeEncoder.encode("EX"),
                        ApplicationProtocolConfig.Protocol.toByteArray(exptime));
                return obj != null;
            }
        });
        return b;
    }*/
}
